import * as types from "./mutation-types";
import Api from "api/api";
import _ from "lodash";
const state = {
  rooms: {},
  currentRoom: {}
};

const getters = {
  rooms: state => state.rooms,
  currentRoom: state => state.currentRoom
};

const actions = {
  getControlRoomPageS({ commit }, param) {
    return Api.getControlRoomPage(param).then(ret => {
      commit(types.UPDATE_ROOMS, ret.data.data);
      return ret;
    });
  },
  getControlRoomS({ commit }, id) {
    return Api.getControlRoom({ id: id }).then(ret => {
      console.log(ret.data.data);
      commit(types.UPDATE_CURRENT_ROOM, ret.data.data);
      return ret;
    });
  },
  addOrUpdateControlRoomS({ commit }, payload) {
    return Api.addOrUpdateControlRoom({ body: payload }).then(ret => {
      return ret;
    });
  },
  deleteControlRoomS({ commit }, param) {
    console.log(param);
    return Api.deleteControlRoom(param).then(ret => {
      return ret;
    });
  }
};

const mutations = {
  [types.INIT_CURRENT_ROOM](state, payload) {
    state.currentRoom = {
      name: "",
      deptId: payload.departId,
      deptName: payload.departName
    };
  },
  [types.UPDATE_ROOMS](state, payload) {
    state.rooms = payload;
  },
  [types.UPDATE_CURRENT_ROOM](state, payload) {
    state.currentRoom = payload;
  }
};
export default {
  state,
  getters,
  actions,
  mutations
};
